package org.pas.fb2.tag;

public class StanzaLineTag extends Tag {
    static final String NAME = "v";
    private final StringBuilder text = new StringBuilder();
    private final boolean indent;

    StanzaLineTag(Tag parent) {
        this(parent, false);
    }

    StanzaLineTag(Tag parent, boolean indent) {
        super(parent);
        this.indent = indent;
    }

    @Override
    public Tag onChild(String name) {
        if (EmphasisTag.NAME.equals(name)) {
            return new EmphasisTag(this);
        }
        return super.onChild(name);
    }

    @Override
    public String getName() {
        return NAME;
    }

    @Override
    protected void doClose() {
        if (indent) {
            out(" " + removeSpaces(text));
        } else {
            out(removeSpaces(text));
        }
    }

    @Override
    public void onChars(char ch[], int start, int length) {
        text.append(ch, start, length);
    }

    public CharSequence getText() {
        return text;
    }
}
